<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:64:"D:\wamp\www\blog\public/../application/admin\view\role\auth.html";i:1517729188;}*/ ?>


<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
    </script>

    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="<?php echo url('admin/index/index'); ?>">首页</a>
        </li>

        <li>用户管理</li>
        <li class="active">分配节点</li>
    </ul><!-- .breadcrumb -->


</div>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <!-- PAGE CONTENT BEGINS -->

            <div class="row">
                <div class="col-xs-12">
                    <div class="table-responsive">
                        <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>角色</th>
                                <th>描述</th>
                                <th>节点</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody>
                            <?php if(is_array($data) || $data instanceof \think\Collection || $data instanceof \think\Paginator): $i = 0; $__LIST__ = $data;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$info): $mod = ($i % 2 );++$i;?>
                            <tr>
                                <td><?php echo $info['id']; ?></td>
                                <td><?php echo $info['name']; ?></td>
                                <td><?php echo $info['remark']; ?></td>
                                <td class="par-noded">
                                    <?php if(is_array($info['node']) || $info['node'] instanceof \think\Collection || $info['node'] instanceof \think\Paginator): $i = 0; $__LIST__ = $info['node'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$node): $mod = ($i % 2 );++$i;?>
                                    <span style="margin: 0 5px;" class="noded"><?php echo $node; ?></span>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </td>
                                <td>
                                    <a  role="button"  class="green editForm" data-toggle="modal"> <i class="icon-edit bigger-120"></i> </a>
                                </td>
                            </tr>
                            <?php endforeach; endif; else: echo "" ;endif; ?>
                            </tbody>
                        </table>
                    </div><!-- /.table-responsive -->
                </div><!-- /span -->
            </div><!-- /row -->

        </div>
    </div><!-- /.row -->
</div><!-- /.page-content -->

<script>



    //表单回填
    $(function(){
        $('.editForm').click(function(){
            var id = $(this).parent().siblings().eq(0).html();
            var flag = true;
            if(flag){
                $("<input type='hidden' id='id' name='id' value='"+id+"'>").prependTo('#edit-form');
                flag = false;
            }else{
                $('id').attr({'value':id });
            }



            //模态框表单回填
            var arr = [];
            var nodes = [];
            ($(this).parent().siblings().eq(3).children('.noded')).each(function ()  {
                arr.push($(this).html());
            });
            $('.nodes').each(function(){
                if($.inArray($(this).html(),arr) != -1){
                    $(this).siblings('.node-val').attr({'checked':'checked'});
                }else{
                    $(this).siblings('.node-val').removeAttr('checked');
                }

            });

            $(this).attr({'href' : '#modal-table'});
        });
    });
</script>


<div id="modal-table" class="modal fade" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">&times;</span>
                    </button>
                    编辑
                </div>
            </div>

            <div class="modal-body no-padding">
                <form class="form-horizontal" style="margin-top: 30px;" id="edit-form">
                    <div class="form-group">
                        <div class="control-group">
                            <label class="col-sm-3 control-label no-padding-right"> 分配角色： </label>
                            <div class="col-sm-9">
                                <?php if(is_array($nodes) || $nodes instanceof \think\Collection || $nodes instanceof \think\Paginator): $i = 0; $__LIST__ = $nodes;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$info): $mod = ($i % 2 );++$i;?>
                                <label style="margin: 0 5px;">
                                    <span class="lbl nodes"><?php echo $info['name']; ?></span>
                                    <input name="node[]" class="node-val" value="<?php echo $info['id']; ?>" type="checkbox" />
                                </label>
                                <?php endforeach; endif; else: echo "" ;endif; ?>
                            </div>
                        </div>
                    </div>


                    <div class="clearfix" style="margin-bottom: 30px;">
                        <div class="col-md-offset-3 col-md-9">
                            <button class="btn btn-info btn-doedit" type="button">
                                <i class="icon-ok bigger-110 edit"></i>
                                提交
                            </button>
                        </div>
                    </div>
                </form>

            </div>
            <div class="modal-footer no-margin-top">
                <button class="btn btn-sm btn-danger pull-right" id="btn-close" data-dismiss="modal">
                    <i class="icon-remove"></i>
                    Close
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- PAGE CONTENT ENDS -->


<script>
    $('.btn-doedit').click(function(){
        var id = $('#id').val();
        var info = $('#edit-form input').serialize();
        $.ajax({
            type : 'put',
            url : "/a_node/"+id,
            data : info,
            datatype : 'json',
            success : function(data){
                if(data.status){
                    alert('修改成功');
                    $('#btn-close').click();
                    setTimeout(function(){
                        $('#showauth-node').click();
                    },300);
                }else{
                    alert('修改失败');
                }
            },
            error : function(){
                alert('请求失败！');
            }
        });
    });




</script>


